package com.returnsoft.security.converter;

import java.util.List;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import com.returnsoft.security.controller.SessionBean;
import com.returnsoft.security.dto.PermissionDto;

//@FacesConverter(value="permissionConverter")
public class PermissionConverter /*implements Converter*/ {
	

	/*@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String idValue) {
		
		Integer id = Integer.parseInt(idValue);
		SessionBean session = (SessionBean) FacesContext
				.getCurrentInstance().getExternalContext().getSessionMap()
				.get("sessionBean");
		List<PermissionDto> permissions = session.getPermissions();
		PermissionDto permission = null;
		
		for (PermissionDto permissionDto : permissions) {
			if (permissionDto.getId().equals(id)) {
				permission=permissionDto;
				break;
			}
		}
	
		return permission;
		
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object object) {
		Integer id = ((PermissionDto)object).getId();
		return id.toString();
	}*/

	

}
